package org.opengoofy.index12306.framework.starter.idempotent.core;

import org.opengoofy.index12306.framework.starter.bases.ApplicationContextHolder;
import org.opengoofy.index12306.framework.starter.idempotent.core.param.IdempotentParamService;
import org.opengoofy.index12306.framework.starter.idempotent.core.spel.IdempotentSpELByMQExecuteHandler;
import org.opengoofy.index12306.framework.starter.idempotent.core.spel.IdempotentSpELByRestAPIExecuteHandler;
import org.opengoofy.index12306.framework.starter.idempotent.core.token.IdempotentTokenService;
import org.opengoofy.index12306.framework.starter.idempotent.enums.IdempotentSceneEnum;
import org.opengoofy.index12306.framework.starter.idempotent.enums.IdempotentTypeEnum;

/**
 * @author ling007
 * @date 2024/5/27 15:09
 * @desciption: 幂等执行处理器工厂
 */
public final class IdempotentExecuteHandlerFactory {

    /**
     * 获取幂等执行处理器
     * @param scene 指定幂等验证场景类型
     * @param type  指定幂等处理类型
     * @return  幂等执行处理器
     */
    public static IdempotentExecuteHandler getInstance(IdempotentSceneEnum scene, IdempotentTypeEnum type) {
        IdempotentExecuteHandler result = null;

        switch (scene){
            case RESTAPI ->{
                switch (type){
                    case PARAM -> result = ApplicationContextHolder.getBean(IdempotentParamService.class);
                    case TOKEN -> result = ApplicationContextHolder.getBean(IdempotentTokenService.class);
                    case SPEL -> result = ApplicationContextHolder.getBean(IdempotentSpELByRestAPIExecuteHandler.class);
                    default ->{}
                }
            }
            case MQ -> result = ApplicationContextHolder.getBean(IdempotentSpELByMQExecuteHandler.class);
            default ->{}
        }

        return result;
    }
}
